package ch.unifr.diuf.webeng.taskmap.client;

import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.DialogBox;

public class LoginAsyncCallback implements AsyncCallback<String>{
	
	private DialogBox dialogBox;
	private TaskMap t;
	public LoginAsyncCallback(DialogBox dialogBox, TaskMap t){
		this.dialogBox = dialogBox;
		this.t=t;
	}

	@Override
	public void onFailure(Throwable caught) {
		dialogBox.setText("Error while logging in.");
		
	}

	@Override
	public void onSuccess(String result) {
		String existingUser = (String) result;
		if(result!= null){
			dialogBox.setText("Welcome "+ existingUser);
//			t.loadAfterLogin(dialogBox);
			t.loadAfterLogin();
		} else {
			dialogBox.setText("Invalid username or password" );
		}
		
	}

}
